import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static java.lang.System.out;

public class StartAndEndMethods {
	
	private static final String REGEX = "img(\\d*)\\.(png|gif|jpg)";
	private static final String INPUT =
	      "img001.png img002.gif img.png img.tmp img2.jpg img.txt";
	
	public static void main(String[] args) {
		Pattern p = Pattern.compile(REGEX);
		Matcher m = p.matcher(INPUT);
		int count = 0;
		while(m.find()) {
		    count++;
		    out.println("\nMatch number "+count);
		    out.println("start(): "+m.start() + " , end(): "+m.end());
		    out.println("String matched : " +
		                       INPUT.substring(m.start(), m.end()));
		}

	}

}
